import axios from 'axios';

const isProd = import.meta.env.MODE === 'production';
const instance = axios.create({
  // 生产环境下会自动将服务器的ip拼接/api前
  baseURL: isProd ? '/api' 
  : 'http://localhost:8234/api',
  timeout: 10000,
});

export function getMessageList(chatId) {
  return instance.get('/ai/chat/list', { params: { chatId } });
}

export function doChatWithLoveAppSse(message, chatId) {
  return new EventSource(
    `${instance.defaults.baseURL}/ai/love-app/chat/sse?message=${encodeURIComponent(message)}&chatId=${chatId}`
  );
}

export function doChatWithManusSse(message) {
  return new EventSource(
    `${instance.defaults.baseURL}/ai/manus/chat?message=${encodeURIComponent(message)}`
  );
}

export default instance; 